<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class WordResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            "id" => $this->id,
            'book_id' => $this->book_id,
            "word" => $this->word,
            "phonetic_us" => $this->phonetic_us,
            "phonetic_uk" => $this->phonetic_uk,
            "speech_uk" => $this->speech($this->speech_uk),
            "speech_us" => $this->speech($this->speech_us),
            "cover" => $this->cover,
            "trans" => WordTransResource::collection($this->trans),
            'phrases' => WordPhrasesResource::collection($this->phrases),
            'sentences' => WordSentencesResource::collection($this->sentences),
        ];
    }
}
